import base64
import os
import re
import hashlib
import itertools
import json
import textwrap
import uuid
try:
    import sass as libsass
except ImportError:
    libsass = None

from datetime import datetime
from subprocess import Popen, PIPE
from collections import OrderedDict
from odoo import fields, tools, SUPERUSER_ID
from odoo.tools.pycompat import string_types, to_text
from odoo.http import request
from odoo.modules.module import get_resource_path
from .qweb import escape
import psycopg2
from odoo.tools import func, misc

import logging
_logger = logging.getLogger(__name__)

MAX_CSS_RULES = 4095

class CompileError(RuntimeError): pass
def rjsmin(script):
    pass

class AssetError(Exception):
    pass

class AssetNotFound(AssetError):
    pass

class AssetsBundle(object):
    rx_css_import = re.compile("(@import[^;{]+;?)", re.M)
    rx_preprocess_imports = re.compile("""(@import\s?['"]([^'"]+)['"](;?))""")
    rx_css_split = re.compile("\/\*\! ([a-f0-9-]+) \*\/")

    def __init__(self, name, files, remains=None, env=None):
        pass

    def to_html(self, sep=None, css=True, js=True, debug=False, async_load=False, url_for=(lambda url: url)):
        pass

    def to_node(self, css=True, js=True, debug=False, async_load=False):
        pass

    @func.lazy_property
    def last_modified(self):
        pass

    @func.lazy_property
    def version(self):
        return self.checksum[0:7]

    @func.lazy_property
    def checksum(self):
        pass

    def _get_asset_template_url(self):
        pass

    def _get_asset_url_values(self, id, unique, extra, name, page, type):
        pass

    def get_asset_url(self, id='%', unique='%', extra='', name='%', page='%', type='%'):
        pass

    def clean_attachments(self, type):
        pass

    def get_attachments(self, type, ignore_version=False):
        pass

    def save_attachment(self, type, content, inc=None):
        pass

    def js(self):
        pass

    def css(self):
        pass

    def dialog_message(self, message):
        pass

    def _get_assets_domain_for_already_processed_css(self, assets):
        pass

    def is_css_preprocessed(self):
        pass

    def preprocess_css(self, debug=False, old_attachments=None):
        pass

    def compile_css(self, compiler, source):
        pass

    def run_rtlcss(self, source):
        pass

    def get_preprocessor_error(self, stderr, source=None):
        pass

    def get_rtlcss_error(self, stderr, source=None):
        pass

class WebAsset(object):
    html_url_format = '%s'
    _content = None
    _filename = None
    _ir_attach = None
    _id = None

    def __init__(self, bundle, inline=None, url=None, filename=None):
        pass

    @func.lazy_property
    def id(self):
        pass

    @func.lazy_property
    def name(self):
        pass

    @property
    def html_url(self):
        pass

    def stat(self):
        pass

    def to_html(self):
        pass

    def to_node(self):
        pass

    @func.lazy_property
    def last_modified(self):
        pass

    @property
    def content(self):
        pass

    def _fetch_content(self):
        pass

    def minify(self):
        pass

    def with_header(self, content=None):
        pass

class JavascriptAsset(WebAsset):
    def minify(self):
        pass

    def _fetch_content(self):
        pass

    def to_node(self):
        pass

class StylesheetAsset(WebAsset):
    rx_import = re.compile(r"""@import\s+('|")(?!'|"|/|https?://)""", re.U)
    rx_url = re.compile(r"""url\s*\(\s*('|"|)(?!'|"|/|https?://|data:)""", re.U)
    rx_sourceMap = re.compile(r'(/\*# sourceMappingURL=.*)', re.U)
    rx_charset = re.compile(r'(@charset "[^"]+";)', re.U)

    def __init__(self, *args, **kw):
        pass

    @property
    def content(self):
        pass

    def _fetch_content(self):
        pass

    def get_source(self):
        pass

    def minify(self):
        pass

    def to_node(self):
        pass

class PreprocessedCSS(StylesheetAsset):
    rx_import = None

    def __init__(self, *args, **kw):
        pass

    def get_command(self):
        pass

    def compile(self, source):
        pass

class SassStylesheetAsset(PreprocessedCSS):
    rx_indent = re.compile(r'^( +|\t+)', re.M)
    indent = None
    reindent = '    '

    def minify(self):
        pass

    def get_source(self):
        pass

    def get_command(self):
        pass

class ScssStylesheetAsset(PreprocessedCSS):
    @property
    def bootstrap_path(self):
        return get_resource_path('web', 'static', 'lib', 'bootstrap', 'scss')

    precision = 8
    output_style = 'expanded'

    def compile(self, source):
        pass

    def get_command(self):
        pass

class LessStylesheetAsset(PreprocessedCSS):
    def get_command(self):
        pass
